package com.seeyon.apps.kk.listener;

import com.seeyon.apps.collaboration.event.CollaborationFinishEvent;
import com.seeyon.apps.collaboration.po.ColSummary;
import com.seeyon.apps.kk.manager.LockEaPricesManager;
import com.seeyon.ctp.common.po.template.CtpTemplate;
import com.seeyon.ctp.util.annotation.ListenEvent;
import com.seeyon.kk.utils.ValueUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LockEaPricesListener extends BaseListener{
	  private static final Log log = LogFactory.getLog(LockEaPricesListener.class);
	  private LockEaPricesManager lepmanager;
	  
	  public LockEaPricesManager getLepmanager(){
	    return this.lepmanager;
	  }
	
	  public void setLepmanager(LockEaPricesManager lepmanager) {
	    this.lepmanager = lepmanager;
	  }
	
	  @ListenEvent(event=CollaborationFinishEvent.class, async=true)
	  public void oneStart(CollaborationFinishEvent event) throws Exception {
	    Thread.sleep(BaseListener.LISTENER_THREAD_SLEEPTIME);
	
	    String templetSubject = ValueUtils.getConfig().getString("kk.LockEaPricesListener");
	
	    ColSummary summary = this.colManager.getColSummaryById(event.getSummaryId());
	    CtpTemplate template = this.templateManager.getCtpTemplate(summary.getTempleteId());
	    String[] templetSubjects = StringUtils.split(templetSubject, ",");
	
	    if (ArrayUtils.contains(templetSubjects, template.getTempleteNumber())) {
	      Long id = summary.getFormRecordid();
	      this.lepmanager.addEaPricesForm(id);
	    }
	  }
}